home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue54 / Clinic / Grid32U.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1999-12-28  |  1.5 KB  |  59 lines

  1. unit Grid32U;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   Grids, DBGrids, Db, DBTables;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Table1: TTable;
  12.     DataSource1: TDataSource;
  13.     DBGrid1: TDBGrid;
  14.     procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  15.       DataCol: Integer; Column: TColumn; State: TGridDrawState);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28.  
  29. procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  30.   DataCol: Integer; Column: TColumn; State: TGridDrawState);
  31. var
  32.   DataSet: TDataSet;
  33. begin
  34.   with (Sender as TDBGrid) do
  35.   begin
  36.     DataSet := Column.Field.DataSet;
  37.     //Our criteria means green cells, but if the cell is selected,
  38.     //stick with the default blue background but use green font.
  39.     if DataSet.FieldByName('TaxRate').AsFloat > 0 then
  40.     begin
  41.       //Selection might be due to multi-selection,
  42.       //which needs separate checking.
  43.       if (dgMultiSelect in Options) and
  44.          (SelectedRows.IndexOf(DataSet.Bookmark) <> -1) then
  45.         Include(State, gdSelected);
  46.       if (gdSelected in State) then
  47.         Canvas.Font.Color := clGreen
  48.       else
  49.       begin
  50.         Canvas.Brush.Color := clGreen;
  51.         Canvas.Font.Color := clWhite;
  52.       end
  53.     end;
  54.     DefaultDrawColumnCell(Rect, DataCol, Column, State)
  55.   end
  56. end;
  57.  
  58. end.
  59.